class Register{
  constructor(){
    this.submit()
  }

  submit(){
    $('#register-form').on('submit',(e)=>{
      const username =$('#inputUsername').val()
      const password =$('#inputPassword').val()

      var formData = new FormData()
      formData.append('username',$('#inputUsername').val())
      formData.append('password',$('#inputPassword').val())
      formData.append('avatar',$('#inputAvatar')[0].files[0])
      $.ajax({
        url:'/api/v1/user/register',
        method:'POST',
        data:formData,
        processData:false,
        contentType:false,
        success:resp=>{
          console.log(resp)
          if(resp.code===200){
            alert('注册成功')
            window.location.href='./login.html'
          }
        },
        dataType:'json'
      })
      e.preventDefault()
    })
  }
}
new Register()

